package homework.xuluoxi;

/*
 * 作业名称：斗地主（非完整）
 * 作业功能：实现简易斗地主部分功能
 * 分　　类：系统框架
 * 学　　员：徐罗希
 * 版　　本：V1.0
 * 备　　注：模块三作业
 */

import java.util.ArrayList;

public class CardGame {

    public static void main(String[] args) {

        // 1、准备游戏过程中会用到的参数变量
        String playerName;
        ArrayList<Card> lastCard = new ArrayList<>();

        // 2、准备扑克牌组并洗牌
        CardList cardList = new CardList();
        cardList.cardListReady();
        cardList.cardShuffle();

        // 3、初始化三位玩家
        Player p1 = Player.PLAYER1;
        Player p2 = Player.PLAYER2;
        Player p3 = Player.PLAYER3;

        // 4、发牌
        playerName = "张三";
        for (Card c : cardList.getCardList()) {
            if(p1.getName().equals(playerName)) {
                p1.getPlayList().add(c);
                playerName = "李四";
            }
            else if(p2.getName().equals(playerName)) {
                p2.getPlayList().add(c);
                playerName = "王五";
            }
            else if(p3.getName().equals(playerName)) {
                p3.getPlayList().add(c);
                playerName = "张三";
            }

            // 动态展示玩家手牌
            CardList.showPlayCard(p1);
            CardList.showPlayCard(p2);
            CardList.showPlayCard(p3);
            System.out.println("-----------------------------------------------------------------------");

            if (p1.getPlayList().size() == 17 && p2.getPlayList().size() == 17 && p3.getPlayList().size() == 17) {
                break;
            }
        }

        System.out.print("底牌为：");
        for (int i = 51; i <= 53; i ++) {
            lastCard.add(cardList.getCardList().get(i));
        }
        CardList.showPlayCard(lastCard);
        System.out.println("-----------------------------------------------------------------------");

        // 5、手牌排序
        System.out.println("玩家手牌排序后");
        p1.setPlayList(CardList.cardSort(p1.getPlayList()));
        p2.setPlayList(CardList.cardSort(p2.getPlayList()));
        p3.setPlayList(CardList.cardSort(p3.getPlayList()));
        CardList.showPlayCard(p1);
        CardList.showPlayCard(p2);
        CardList.showPlayCard(p3);
        System.out.print("底牌为：");
        lastCard = CardList.cardSort(lastCard);
        CardList.showPlayCard(lastCard);
    }
}
